package com.lw.extraceim.ui.fragments;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.lw.extraceim.R;
import com.lw.extraceim.app.ExtraceApplication;
import com.lw.extraceim.model.ExpressSheet;
import com.lw.extraceim.ui.adapter.ExtraceFragmentPagerAdapter;
import com.lw.extraceim.ui.fragments.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class TaskFragment extends BaseFragment {
    private static final String TAG = "TransportFragment";

    private TabLayout mTabLayout;
    private ViewPager mViewPager;

    private ArrayList<ExpressSheet> transPackages;//真正的数据
    public static final int RESULT_FROM_TRANSPORTINFOACTIVITY = 105;

    private List<BaseFragment> fragmentArrayList; //fragment列表
    private List<String> titleList; //顶部导航

    private ExtraceFragmentPagerAdapter adapter;

    private MyTransFragment myTransFragment;
    private MyDispatchFragment myDeliverFragment;

    public TaskFragment(Context mContext, ExtraceApplication application) {
        super(mContext, application);
    }

    @Override
    public View initView() {
        View view = View.inflate(mContext, R.layout.layout_task_fragment, null);
        mTabLayout = view.findViewById(R.id.tab_layout);
        mViewPager = view.findViewById(R.id.view_pager);
        return view;
    }

    /*
        注册事件
     */
    @Override
    public void initEvent() {
    }

    /*
     * 初始化数据
     * */
    @Override
    public void initData() {
        fragmentArrayList = new ArrayList<>();
        myTransFragment = new MyTransFragment(getContext(), application);
        myDeliverFragment = new MyDispatchFragment(getContext(), application);
        fragmentArrayList.add(myTransFragment);
        fragmentArrayList.add(myDeliverFragment);

        titleList = new ArrayList<>();
        titleList.add("我的转运");
        titleList.add("我的派送");

        adapter = new ExtraceFragmentPagerAdapter(getChildFragmentManager(), fragmentArrayList, titleList);
        mViewPager.setAdapter(adapter);
        mTabLayout.setupWithViewPager(mViewPager);//将TabLayout与Viewpager联动起来
    }

    @Override
    public void refreshUI() {

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.d(TAG, "onActivityResult: " + requestCode);
    }
}
